package refund

import java.util.function.{Consumer, Predicate}

import com.alipay.api.AlipayClient
import com.trjcn.wxpay.service.WXPayService
import config.{AliPayProperties, WXPayProperties}
import dto.req.{NotifyReqDTO, RefundOrderReqDTO}
import enums.PayEnum
import factory.{ActionFactory, RefundAction}
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import utils.AssertUtils

abstract class BaseRefundAction extends RefundAction{

  protected val log = LoggerFactory.getLogger(this.getClass)

  protected var alipayClient:AlipayClient = null

  protected var aliPayProperties:AliPayProperties = null

  protected var wxPayProperties:WXPayProperties = null

  protected var wxPayService:WXPayService = null

  override def setProperties(bizCode: String): Unit = {
    aliPayProperties = ActionFactory.getAliPayProperties(bizCode)
    wxPayProperties =ActionFactory.getWXPayProperties(bizCode)
    wxPayService = wxPayProperties.getWXPayService
    alipayClient = aliPayProperties.getAlipayClient
  }

  override def checkParams[T <: RefundOrderReqDTO](req: T): Unit = {
    AssertUtils.notNull(req)
    AssertUtils.notNull(req.getPayChannel, "payChannel 不能为空")
    AssertUtils.notNull(req.getOriPayOrderNo, "oriPayOrderNo 不能为空")
    AssertUtils.notNull(req.getPayAmount, "payAmount 不能为空")
    AssertUtils.notNull(req.getPayAmount, "refundAmount 不能为空")
  }

  override def refundTransaction(req: RefundOrderReqDTO, consumer: Consumer[RefundOrderReqDTO]): Unit = {
    consumer.accept(req)
  }

  override def callback(req: NotifyReqDTO, predicate: Predicate[NotifyReqDTO]): Boolean = {
    predicate.test(req)
  }
}
